home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / curves.c.bak < prev    next >
Text File  |  1994-07-15  |  3KB  |  191 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. /*
  13.  * curve basis types
  14.  */
  15. Matrix    bezier = {
  16.     {-1.0,    3.0,    -3.0,    1.0},
  17.     {3.0,    -6.0,    3.0,    0.0},
  18.     {-3.0,    3.0,    0.0,    0.0},
  19.     {1.0,    0.0,    0.0,    0.0} 
  20. };
  21.  
  22. Matrix    cardinal = {
  23.     {-0.5,    1.5,    -1.5,    0.5},
  24.     {1.0,    -2.5,    2.0,    -0.5},
  25.     {-0.5,    0.0,    0.5,    0.0},
  26.     {0.0,    1.0,    0.0,    0.0}
  27. };
  28.  
  29. Matrix    bspline = {
  30.     {-1.0 / 6.0,    3.0 / 6.0,    -3.0 / 6.0,    1.0 / 6.0},
  31.     {3.0 / 6.0,    -6.0 / 6.0,    3.0 / 6.0,    0.0},
  32.     {-3.0 / 6.0,    0.0,        3.0 / 6.0,    0.0},
  33.     {1.0 / 6.0,    4.0 / 6.0,    1.0 / 6.0,    0.0}    
  34. };
  35.  
  36. /*
  37.  *     Geometry matrix to demonstrate basic spline segments
  38.  */
  39. float   geom1[4][3] = {
  40.     { -180.0, 10.0, 0.0 },
  41.     { -100.0, 110.0, 0.0 },
  42.     { -100.0, -90.0, 0.0 },
  43.     { 0.0, 50.0, 0.0 }
  44. };
  45.  
  46. /*
  47.  *     Geometry matrix to demonstrate overlapping control points to
  48.  *    produce continuous (Well, except for the bezier ones) curves
  49.  *    from spline segments
  50.  */
  51. float    geom2[6][3] = {
  52.     { 200.0, 480.0, 0.0 },
  53.     { 380.0, 180.0, 0.0 },
  54.     { 250.0, 430.0, 0.0 },
  55.     { 100.0, 130.0, 0.0 },
  56.     { 50.0,  280.0, 0.0 },
  57.     { 150.0, 380.0, 0.0 }
  58. };
  59.  
  60. /*
  61.  * using curves
  62.  */
  63. int main(void)
  64. {
  65.     char    dev[20];
  66.     int    i;
  67.     short    val;
  68.  
  69.     winopen("curves");
  70.  
  71.     qdevice(KEYBD);
  72.     unqdevice(INPUTCHANGE);
  73.  
  74.     ortho2(-200.0, 400.0, -100.0, 500.0);
  75.  
  76.     color(BLACK);
  77.     clear();
  78.  
  79.     color(YELLOW);
  80.  
  81.     /*
  82.      * label the control points in geom1
  83.      */
  84.         for (i = 0; i < 4; i++) {
  85.         cmov2(geom1[i][0], geom1[i][1]);
  86.         sprintf(dev, "%d", i);
  87.         charstr(dev);
  88.     }
  89.                                  
  90.     /*
  91.      * label the control points in geom2
  92.      */
  93.     for (i = 0; i < 6; i++) {
  94.         cmov2(geom2[i][0], geom2[i][1]);
  95.         sprintf(dev, "%d", i);
  96.         charstr(dev);
  97.     }
  98.  
  99.     /*
  100.      * set the number of line segments appearing in each curve to 20
  101.      */
  102.     curveprecision((short)20);
  103.  
  104.     /*
  105.      * copy the bezier basis matrix into the basis matrix stack and
  106.      * set the curve basis accordingly.
  107.      */
  108.     defbasis((short)1, bezier);
  109.     curvebasis((short)1);
  110.  
  111.     color(RED);
  112.  
  113.     /*
  114.      * draw a curve using the current basis matrix (bezier in this case)
  115.      * and the control points in geom1
  116.      */
  117.     crv(geom1);
  118.  
  119.     cmov2(70.0, 60.0);
  120.     charstr("Bezier Curve Segment");
  121.  
  122.     cmov2(-190.0, 450.0);
  123.     charstr("Three overlapping Bezier Curves");
  124.  
  125.     /*
  126.      * crvn draws overlapping curve segments according to geom2, the
  127.      * number of curve segments drawn is three less than the number of
  128.      * points passed, assuming there are a least four points in the
  129.      * geometry matrix (in this case geom2). This call will draw 3
  130.      * overlapping curve segments in the current basis matrix - still
  131.      * bezier.
  132.      */
  133.     crvn(6L, geom2);
  134.  
  135.     qread(&val);
  136.  
  137.     /*
  138.      * load in the cardinal basis matrix
  139.      */
  140.     defbasis((short)1, cardinal);
  141.     curvebasis((short)1);
  142.  
  143.     color(MAGENTA);
  144.  
  145.     cmov2(70.0, 10.0);
  146.     charstr("Cardinal Curve Segment");
  147.  
  148.     /*
  149.      * plot out a curve segment using the cardinal basis matrix
  150.      */
  151.     crv(geom1);
  152.  
  153.     cmov2(-190.0, 400.0);
  154.     charstr("Three overlapping Cardinal Curves");
  155.  
  156.     /*
  157.      * now draw a bunch of them again.
  158.      */
  159.     crvn(6L, geom2);
  160.  
  161.     qread(&val);
  162.  
  163.     /*
  164.      * change the basis matrix again
  165.      */
  166.     defbasis((short)1, bspline);
  167.     curvebasis((short)1);
  168.  
  169.     color(GREEN);
  170.  
  171.     cmov2(70.0, -40.0);
  172.     charstr("Bspline Curve Segment");
  173.  
  174.     /*
  175.      * now draw our curve segment in the new basis...
  176.      */
  177.     crv(geom1);
  178.  
  179.     cmov2(-190.0, 350.0);
  180.     charstr("Three overlapping Bspline Curves");
  181.  
  182.     /*
  183.      * ...and do some overlapping ones
  184.      */
  185.     crvn(6L, geom2);
  186.  
  187.     qread(&val);
  188.  
  189.     gexit();
  190. }
  191.